//
//  MainView.swift
//  cysLibrarySys
//
//  Created by 曹亚索 on 2021/6/24.
//

import Foundation
import UIKit
//用户
var userSelf : User?
var localLibrary = LocalLibrary()


//本地书库
class LocalLibrary {
    var allBook : [Book] = []
}


//MARK:User
class User{
    private var _name : String?
    private var _avatar : String?
    private var _borrow : [Book] = []
    private var _collection : [Book] = []
    private var _share : [Book] = []
    
    var name : String?{
        get{
            return _name
        }set{
            _name = newValue
        }
    }
    var avatar : String?{
        get{
            return _avatar
        }set{
            _avatar = newValue
        }
    }
    var borrow : [Book]{
        get{
            return _borrow
        }set{
            _borrow = newValue
        }
    }
    var collection : [Book]{
        get{
            return _collection
        }set{
            _collection = newValue
        }
    }
    var share : [Book]{
        get{
            return _share
        }set{
            _share = newValue
        }
    }
    
    init(username:String,avatar:String?){
        self.name = username
        self.avatar = avatar
        
    }
}


//MARK:Book
class Book{
    
    private var _index : Int!
    private var _face : UIImage?
    private var _name : String?
    private var _author : String?
    private var _abstract : String?
    private var _collectedTime : String?
    private var _state : bookState!
    
    var index : Int{
        get{
            return _index
        }set{
            _index = newValue
        }
    }
    var face : UIImage?{
        get{
            return _face
        }set{
            _face = newValue
        }
    }
    var name : String?{
        get{
            return _name
        }set{
            _name = newValue
        }
    }
    var author : String?{
        get{
            return _author
        }set{
            _author = newValue
        }
    }
    var abstract : String?{
        get{
            return _abstract
        }set{
            _abstract = newValue
        }
    }
    var collectedTime : String?{
        get{
            return _collectedTime
        }set{
            _collectedTime = newValue
        }
    }
    var state : bookState{
        get{
            return _state
        }set{
            _state = newValue
        }
    }
    
    init(face:UIImage?,name:String?,author:String?,abstract:String?) {
        if face != nil{
            self.face = face
        }else{
            self.face = #imageLiteral(resourceName: "Password-hide")
        }
        self.name = name
        self.author = author
        self.abstract = abstract
        self.state = .init()
    }
    
    struct bookState {
        
        var isCollected : Bool
        var isBorrowed : Bool
        
        init() {
            isCollected = false
            isBorrowed = false
        }
    }
}


